<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>promise</title>
</head>
<body>
<script type="text/javascript">

   /* var getJSON = function(url) {
        var promise = new Promise(function(resolve, reject){
            var client = new XMLHttpRequest();
            client.open("GET", url);
            client.onreadystatechange = handler;
            client.responseType = "json";
            client.setRequestHeader("Accept", "application/json");
            client.send();
            function handler() {

                if (this.status === 200) {
                    resolve(this.response);
                } else {
                    reject(new Error(this.statusText));
                }
            };
        });
        return promise;
    };
    getJSON("./posts.json").then(function(json) {
        console.log('Contents: ' );
        console.log(json);
    }, function(error) {
        console.error('出错了', error);
    });


    var p = Promise.reject('21321321');
    p.then(function (s){
        console.log(s)
    },function (s){
        console.log(s)
    });*/
    // Hello








    //--------------------------------------测试
  /*  console.log(1);
    new Promise(function (resolve, reject){
        reject(true);
        window.setTimeout(function (){
            resolve(true);
        }, 0);
    }).then(function(){
        console.log(2);
    }, function(){
        console.log(3);
    });
    console.log(4);*/



    console.log(1111)
    setTimeout(()=>{
        console.log(2222)
    },0)
    new Promise((res,rej)=>{
        console.log(333333);
        setTimeout(()=>{
            res("success3223")
            console.log(4444)
        },0)
      /*  var xhr = new XMLHttpRequest();
        xhr.onreadystatechange=function () {
            if(xhr.readyState==4){
                if(xhr.readyState==200){
                    res("success3223")
                }else{
                    rej("error")
                }
            }
        }
        xhr.open('GET','./posts.json')
        xhr.send()*/
    }).then(function () {
        console.log(555555555)
    })

</script>

</body>
</html>